import Router from 'vue-router'
import router from './router'
import store from "./store";

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err)
}


const seoPathInfos = [
	// { type: 0, path: "/" },
	{ type: 1, path: "/goods" },
	{ type: 2, path: "/news" },
	{ type: 3, path: "/ability/demand" },
	{ type: 4, path: "/ability/supply" },
	{ type: 5, path: "/ability/project-cooperation" },
	{ type: 6, path: "/industry/meeting" },
	{ type: 7, path: "/industry/exhibition" },
	{ type: 8, path: "/industry/salon" },
	{ type: 9, path: "/industry/alliance" },
	{ type: 10, path: "/patent/supply" },
	{ type: 11, path: "/patent/demand" },
	{ type: 12, path: "/patent/evaluation-agency" },
	{ type: 13, path: "/forums" },
	{ type: 14, path: "/forums/expert" },
	{ type: 15, path: "/library" },
	{ type: 16, path: "/position" },
]


router.beforeEach((to, from, next) => {
	next()
	updateSeo(to)
})


function updateSeo(to) {
	const seoPathInfo = seoPathInfos.find(info => (to.path).includes(info.path))
	var seoType = 0
	if (seoPathInfo) {
		seoType = seoPathInfo.type
		console.info(`\ntoPath = ${to.path}  seoPath= ${seoPathInfo.path} setType = ${seoType}\n`)
	}
	const parameters = {
		type: seoType,
	}
	store.dispatch("seo/setUpSeo", parameters).then().catch()
}